﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：
    //

    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;


namespace HZ.DrugTrade.Web.Admin.DrugLibManage
{
    public partial class HospitalLoginPriceDetail : System.Web.UI.Page
    {

        IBLL_HospitalLoginPriceGoods ih = Factory.BLL_HospitalLoginPriceGoods();
        public string strGoodsID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                strGoodsID = Request["GoodsID"];//是否填报
                if (string.IsNullOrEmpty(strGoodsID))
                {
                    HZ.Web.WebUtil.Alert("数据获取失败请重试。", this);
                    return;
                }
                bindHospital();
                Bind();

            }
        }

        /// <summary>
        /// 绑定符合条件的采购明细
        /// </summary>
        private void Bind()
        {

            int totalCount;
            IList<Model.View.HospitalLoginPriceGoods> purchaseOrderDetailList = ih.GetGoodsByWhere(GetWhere(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwNoConfirm.PageSize = AspNetPager1.PageSize;
            gvwNoConfirm.DataSource = purchaseOrderDetailList;
            gvwNoConfirm.DataBind();
        }

        /// <summary>
        /// 绑定医疗机构
        /// </summary>
        private void bindHospital()
        {
            string sql = string.Format(@"SELECT distinct HospitalName FROM View_HospitalLoginPrice  Where goodsid='" + strGoodsID + "'");
            System.Data.DataTable dt1 = HZ.Data.DbHelperFactory.Create().ExecuteTable(sql);
            System.Data.DataRow row = dt1.NewRow();
            row[0] = "全部";
            dt1.Rows.InsertAt(row, 0);
            ddl_hospitalname.DataSource = dt1;
            ddl_hospitalname.SelectedIndex = 0;
            ddl_hospitalname.DataTextField = "HospitalName";
            ddl_hospitalname.DataValueField = "HospitalName";
            ddl_hospitalname.DataBind();
            dt1.Dispose();
        }

        public Model.Query.HospitalLoginPriceGoods GetWhere()
        {
            Model.Query.HospitalLoginPriceGoods where = new HZ.DrugTrade.Model.Query.HospitalLoginPriceGoods();

            where.GoodsID = strGoodsID;//流水号
            where.GoodsName = txtGoodsName.Text.Trim();//产品名称
            where.Material = txtMaterial.Text.Trim();//材质
            where.Outlookc = txtOutLook.Text.Trim();
            where.CompanyName_SC = txtCompanyName_Sc.Text.Trim();//生产企业
            where.SortFields = " price asc";

            if (ddl_hospitalname.Text != "全部")
            {
                where.Append = "  HospitalName like'%" + ddl_hospitalname.Text + "%'";
            }
            return where;
        }


        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount;
            IList<Model.View.HospitalLoginPriceGoods> purchaseOrderDetailList = ih.GetGoodsByWhere(GetWhere(), 1, 0, out totalCount);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, gvwNoConfirm);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Bind();
        }

    }

}
